<?php
namespace App\Admin\Controller;

use \Foxforms\Widget\Form;
use \Foxforms\Widget\Field\Input;

class emailController extends \Foxframe\Controller
{
	public function addEmail($params = array())
	{
		$email	= new \Entities\Corp\Email();


		$form	= new Form();
		$form->addValues($email, 'email');
		$form->addElement(Input::create('pessoa[dsemail]')->setLabel('Email')->addClass('email')->validate());
		$this->view->returnAjax();

	}

	public function deletarEmail($params = array())
	{
		try
		{
// 			echo '<pre>';print_r($params);die;
			$email	= $this->em->find('\Entities\Corp\Email', $params['idemail']);
// 			$pessoa	= $email->getPessoa();
// 			$pessoa->getEmails()->removeElement($email);
// 			$this->em->detach($email);
			$this->em->remove($email);
			$this->em->flush();

			//echo $this->setFlash('Success', 'Sucesso', $email->getDsEmail().' excluído com sucesso');
			echo "Sucesso";
		}
		catch (\Exception $e)
		{
			echo $e->getMessage();
// 			echo header("HTTP/1.0 400 ".utf8_encode('Erro ao excluir email'));
		}
		exit;
	}

}